//
//  ViewController.swift
//  C008_test_multi_controller_in_one_page
//
//  Created by yao_yu on 15/5/29.
//  Copyright (c) 2015年 yao_yu. All rights reserved.
//

import UIKit

class ViewController: UIViewController {
    
    var vc1 = ViewControllerContainer()
    
    override func viewDidLoad() {
        super.viewDidLoad()
        // Do any additional setup after loading the view, typically from a nib.'
        vc1.view.backgroundColor = UIColor.yellowColor()

        
        view.addSubview(vc1.view)

    }
    
    override func viewDidLayoutSubviews() {
        super.viewDidLayoutSubviews()
        vc1.view.frame = CGRectMake(20, 20, view.frame.width - 40, view.frame.height - 40)

    }
    
    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }
    
    
}

class ViewControllerContainer: UIViewController {
    
    var vc1 = ViewController2()
    var vc2 = ViewController2()
    
    override func viewDidLoad() {
        super.viewDidLoad()
        // Do any additional setup after loading the view, typically from a nib.'
        vc1.view.backgroundColor = UIColor.redColor()
        vc2.view.backgroundColor = UIColor.blueColor()
        
        view.addSubview(vc1.view)
        view.addSubview(vc2.view)
    }
    
    override func viewDidLayoutSubviews() {
        super.viewDidLayoutSubviews()
        vc1.view.frame = CGRectMake(20, 20, 100, view.frame.height - 40)
        vc2.view.frame = CGRectMake(140, 20, view.frame.width - 160, view.frame.height - 40)
    }
    
    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }
    
    
}


class ViewController2:UIViewController {
    var lblResult = UILabel()
    var btnTest = UIButton(type: UIButtonType.System) as UIButton
    
    override func viewDidLoad() {
        
        
        btnTest.setTitle("测试", forState: UIControlState.Normal)
        btnTest.addTarget(self, action: "onTest", forControlEvents: UIControlEvents.TouchUpInside)
        
        view.addSubview(btnTest)
        view.addSubview(lblResult)
    }
    
    func onTest() {
        lblResult.text = "这是测试内容"
    }
    
    override func viewDidLayoutSubviews() {
        //super.viewDidLayoutSubviews()
        print(view.frame, appendNewline: true)
        btnTest.frame = CGRectMake(20, 20, view.frame.width - 40, 30)
        lblResult.frame = CGRectMake(20, 80, btnTest.frame.width, view.frame.height - 100)
    }
}
